import { http } from '@/api';
import { PORT1 } from '@/api/config/port';
import { ResultData } from '@/api/interface/index';
import {
  AssignedPersonItem,
  RepViolationAction,
  ReqViolationCreate,
  ReqViolationFind,
  ReqViolationGet,
  ReqViolationLinks,
  ReqViolationSearch,
  ViolationDetails,
  ViolationList,
} from '@/api/interface/violation';
import qs from 'qs';

export const Action = (params: RepViolationAction) => {
  return http.post<ResultData>(PORT1 + `/admin/violation/action`, params);
};

export const Actions = (params: RepViolationAction) => {
  return http.post<ResultData>(PORT1 + `/admin/violation/actions`, params);
};

export const Transfer = (params: RepViolationAction) => {
  return http.post<ResultData>(PORT1 + `/admin/violation/transfer`, params);
};

export const Transfers = (params: RepViolationAction) => {
  return http.post<ResultData>(PORT1 + `/admin/violation/transfers`, params);
};

export const CreateFrom = (params: ReqViolationCreate) => {
  return http.post<ResultData>(PORT1 + `/admin/violation/create`, params);
};

export const Export = (params: any) => {
  return http.download(PORT1 + `/admin/violation/export`, params, {
    loading: true,
  });
};

export const Find = (params: ReqViolationFind) => {
  return http.get<Array<ViolationDetails>>(
    PORT1 + `/admin/violation/find?${qs.stringify(params)}`
  );
};

export const findByEid = (params: ReqViolationFind) => {
  return http.get<Array<ViolationDetails>>(
    PORT1 + `/admin/violation/findByEid?${qs.stringify(params)}`
  );
};

export const findByEmail = (params: ReqViolationFind) => {
  return http.get<Array<ViolationDetails>>(
    PORT1 + `/admin/violation/findByEmail?${qs.stringify(params)}`
  );
};

export const Get = (params: ReqViolationGet) => {
  return http.get<ViolationDetails>(
    PORT1 + `/admin/violation/get?${qs.stringify(params)}`
  );
};

export const Search = (params: ReqViolationSearch) => {
  return http.post<ViolationList>(PORT1 + `/admin/violation/search`, params);
};

export const RefViolations = (params: ReqViolationSearch) => {
  return http.post<ViolationList>(
    PORT1 +
      `/admin/violation/ref-violations
  `,
    params
  );
};

export const ActionLog = (params: ReqViolationGet) => {
  return http.post<any>(
    PORT1 + `/admin/violation/action-log?${qs.stringify(params)}`
  );
};

export const ReplyList = (params: ReqViolationGet) => {
  return http.post<any>(
    PORT1 + `/admin/violation/reply/list?${qs.stringify(params)}`
  );
};

export const AssignedPerson = (params: any) => {
  return http.post<Array<AssignedPersonItem>>(
    PORT1 + `/admin/violation/assigned-person`,
    params,
    {
      cancel: false,
    }
  );
};

export const Exists = (params: ReqViolationGet) => {
  return http.get<any>(
    PORT1 + `/admin/violation/exists?${qs.stringify(params)}`
  );
};

export const orgOther = (params: any) => {
  return http.post<any>(PORT1 + `/admin/violation/org/others`, params);
};

export const notice = (params: ReqViolationGet) => {
  return http.get<any>(
    PORT1 + `/admin/violation/reply/notice?${qs.stringify(params)}`
  );
};

export const noticed = (params: ReqViolationGet) => {
  return http.get<any>(
    PORT1 + `/admin/violation/reply/noticed?${qs.stringify(params)}`
  );
};

export const updateAttachment = (params: { fileName: string; id: string }) => {
  return http.post<any>(PORT1 + `/admin/violation/update-attachment`, params, {
    cancel: false,
    loading: true,
  });
};

export const investigations = (params: ReqViolationGet) => {
  return http.get<any>(
    PORT1 + `/admin/violation/investigations?${qs.stringify(params)}`
  );
};

export const DownloadViolation = (params: any) => {
  return http.downloadGet(
    PORT1 + `/admin/download/violation?${qs.stringify(params)}`,
    {
      loading: true,
    }
  );
};

export const DownloadInvestigation = (params: any) => {
  return http.downloadGet(
    PORT1 + `/admin/download/investigation?${qs.stringify(params)}`,
    {
      loading: true,
    }
  );
};
